<template>
  <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
    <van-list v-model="loading" :finished="true" finished-text="没有更多了~" @load="onLoad">
      <div :class="isOddEven ?'shoplist':'shoplists'">
        <div class="list-item" v-for="item in wareList" :key="item.id" @click="goProduct(item)">
          <div class="list-item-left">
            <img :src="item.waresPic" alt="" srcset="" />
          </div>
          <div class="list-item-right">
            <div class="item-right-top">
              <p class="info">{{ item.waresName }}</p>
              <p class="info_waresDetail">{{ item.waresDetail }}</p>
            </div>
            <div class="item-right-bottom">
              <span class="price"><span class="icon"></span>{{ item.saleIntegral }}</span>
              <span class="sold">{{ "库存 " + item.waresCount }}</span>
            </div>
          </div>
        </div>
      </div>
    </van-list>
  </van-pull-refresh>
</template>

<script>
import Vue from "vue";
import { PullRefresh, List } from "vant";
import { mapState, mapActions } from "vuex";

Vue.use(PullRefresh);
Vue.use(List);

export default {
  data() {
    return {
      images: [],
      loading: false, //加载状态
      finished: false, //是否完成加载
      refreshing: false, //是否正在上拉刷新
      isOddEven:false
    };
  },
  props: ["sid","showType"],
  created() {
    console.log("加载了", this.sid);
    if (!!this.sid) {
      this.onLoad();
    }
  },
  computed: {
    ...mapState({
      wareList: state => state.point.wareList
    })
  },
  watch: {
    // 如果 `question` 发生改变，这个函数就会运行
    sid: function() {
      this.onLoad();
    }
  },
  methods: {
    ...mapActions({
      getWareList: "point/getWareList"
    }),
    onLoad() {
      // var that = this;
      this.getWareList(this.sid).then(res => {
        if(res&&res.retCode==0){ 
          this.loading = false;
          this.finished = true;
          this.refreshing=false
        }
      });
          this.refreshing=false
          if(this.showType==2){ 
            this.isOddEven=true
          }else{ 
            this.isOddEven=false
          }
    },

    onRefresh() {
      console.log(234);
      // 清空列表数据
      this.finished = true;
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true;
      this.onLoad();
    },
    goProduct(item) {
      // console.log('/' + this.selectedStation.stationId + '/point/shop');
      this.$router.push({
        path:
          "/" + this.enterpriseId + "/point/detail/" + this.sid + "/" + item.id
      });
    }
  }
};
</script>

<style scoped>
.shoplist {
  width: 92vw;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
}

.shoplist .list-item {
  /* display: flex; */
  margin-top: 30px;
  width: 48%; /* Adjust as needed, considering margins, paddings, and borders */
  margin-bottom: 10px; /* Optional: Add some margin between items */
  box-sizing: border-box;
  justify-items: center;
}
.shoplist .list-item .list-item-left {
  height: 28.5vw;
  border: 0.26vw solid #eeeeee;
  flex-shrink: 0;
}
.shoplist .list-item .list-item-left img {
  display: inline-block;
  width: 100%;
  height: 100%;
  border-radius: 3vw;
}
.shoplist .list-item .list-item-right {
  margin-left: 3vw;
  color: red;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  font-size: 4.266vw;
  font-weight: 400;
  color: #111111;
  line-height: 6vw;
  height: 28.5vw;
}
.shoplist .list-item .list-item-right .item-right-top {
  flex-shrink: 0;
  word-break: break-all;
  height: 1.45rem;
  font-size: 0.32rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #111111;
  line-height: 0.45rem;
}

.shoplist .list-item .list-item-right .item-right-top .info {
  font-weight: 500;
  margin: 0.1rem 0rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.shoplist .list-item .list-item-right .item-right-top .info_waresDetail {
  width: 100%;
  margin: 0.1rem 0rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* Limit the number of lines */
  -webkit-box-orient: vertical;
  white-space: normal;
}

.shoplist .list-item .list-item-right .item-right-bottom {
  /* width: 4.53rem; */
  height: 0.9rem;
  position: relative;
}
.shoplist .list-item .list-item-right .item-right-bottom .price {
  font-size: 0.4rem;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #fe9700;
  line-height: 0.56rem;
  position: absolute;
  left: 0.1rem;
  bottom: 0rem;
}
.shoplist .list-item .list-item-right .item-right-bottom .price .icon {
  display: inline-block;
  width: 0.3rem;
  height: 0.3rem;
  background: url("../static/common/a01_jifen@2x.png") no-repeat;
  background-size: cover;
  margin-right: 0.1rem;
}
.shoplist .list-item .list-item-right .item-right-bottom .sold {
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #bcbcbc;
  line-height: 0.4rem;
  position: absolute;
  right: 0.1rem;
  bottom: 0.03rem;
}
.shoplists {
  width: 92vw;
}

.shoplists .list-item {
  display: flex;
  margin-top: 30px;
  width: 92vw;
  height: 28.5vw;     
}
.shoplists .list-item .list-item-left {
  height: 28.5vw;
  width: 28.5vw;
  border: 0.26vw solid #eeeeee;
  flex-shrink: 0;
}
.shoplists .list-item .list-item-left img {
  display: inline-block;
  width: 100%;
  height: 100%;
  border-radius: 3vw;
}
.shoplists .list-item .list-item-right {
  margin-left: 3vw;
  color: red;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  font-size: 4.266vw;
  font-weight: 400;
  color: #111111;
  line-height: 6vw;
  width: 60.5vw;
  height: 28.5vw;
}
.shoplists .list-item .list-item-right .item-right-top {
  flex-shrink: 0;
  word-break: break-all;
  height: 1.45rem;
  width: 4.53rem;
  font-size: 0.32rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #111111;
  line-height: 0.45rem;
}

.shoplists .list-item .list-item-right .item-right-top .info {
  font-weight: 500;
  margin: 0.1rem 0rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.shoplists .list-item .list-item-right .item-right-top .info_waresDetail {
  width: 100%;
  margin: 0.1rem 0rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2; /* Limit the number of lines */
  -webkit-box-orient: vertical;
  white-space: normal;
}

.shoplists .list-item .list-item-right .item-right-bottom {
  /* width: 4.53rem; */
  height: 0.9rem;
  position: relative;
}
.shoplists .list-item .list-item-right .item-right-bottom .price {
  font-size: 0.4rem;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #fe9700;
  line-height: 0.56rem;
  position: absolute;
  left: 0.1rem;
  bottom: 0rem;
}
.shoplists .list-item .list-item-right .item-right-bottom .price .icon {
  display: inline-block;
  width: 0.3rem;
  height: 0.3rem;
  background: url("../static/common/a01_jifen@2x.png") no-repeat;
  background-size: cover;
  margin-right: 0.1rem;
}
.shoplists .list-item .list-item-right .item-right-bottom .sold {
  height: 0.4rem;
  font-size: 0.28rem;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #bcbcbc;
  line-height: 0.4rem;
  position: absolute;
  right: 0.1rem;
  bottom: 0.03rem;
}
</style>
